package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("/api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	/**
	 * 用户收藏 - MongoDB
	 * @param trackId
	 * @return
	 */
	@GuiguLogin
	@GetMapping("/collect/{trackId}")
	public Result collect(@PathVariable("trackId")Long trackId){
		userInfoService.collect(trackId);
		return Result.ok();
	}

	/**
	 * 用户取消收藏 - MongoDB
	 * @param trackId
	 * @return
	 */
	@GuiguLogin
	@GetMapping("/cancelCollect/{trackId}")
	public Result cancelCollect(@PathVariable("trackId")Long trackId){
		userInfoService.cancelCollect(trackId);
		return Result.ok();
	}


	/**
	 * 查询用户是否收藏了当前声音 - MongoDB
	 * @param trackId
	 * @return
	 */
	@GuiguLogin
	@GetMapping("/isCollect/{trackId}")
	public Result isCollect(@PathVariable("trackId")Long trackId){
		return Result.ok(userInfoService.isCollect(trackId));
	}














	/**
	 * MySQL
	 * 用户收藏
	 * @param trackId
	 * @return
	 */
//	@GuiguLogin
//	@GetMapping("/collect/{trackId}")
	public Result collectMysql(@PathVariable("trackId")Long trackId){
		userInfoService.collectMysql(trackId);
		return Result.ok();
	}

	/**
	 * MySQL
	 * 用户取消收藏
	 * @param trackId
	 * @return
	 */
//	@GuiguLogin
//	@GetMapping("/cancelCollect/{trackId}")
	public Result cancelCollectMysql(@PathVariable("trackId")Long trackId){
		userInfoService.cancelCollectMysql(trackId);
		return Result.ok();
	}


	/**
	 * MySQL
	 * 查询用户是否收藏了当前声音
	 * @param trackId
	 * @return
	 */
//	@GuiguLogin
//	@GetMapping("/isCollect/{trackId}")
	public Result isCollectMysql(@PathVariable("trackId")Long trackId){
		return Result.ok(userInfoService.isCollectMysql(trackId));
	}



}

